//! 生命周期查看器
//!
//! 用户 Debug

use sgs_runtime::{
    executor::{Controller, Event, LifeCycle, Viewer},
    preclude::Delegate,
};

/// Setup 事件委托器
///
/// 通知启动信息
///
/// 返回 [Start::Begin] 事件
///
/// 该委托器仅用于自定义通知信息
#[derive(Clone)]
pub struct LifeCycleDelegator;

impl std::fmt::Debug for LifeCycleDelegator {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "生命周期事件委托器[sgs_pkg_std::LifeCycleDelegator]")
    }
}

impl Delegate for LifeCycleDelegator {
    fn delegate(
        &self,
        event: &Event,
        viewer: &Viewer,
        controller: &mut Controller,
    ) -> Option<Event> {
        match event {
            Event::LifeCycle(event) => delegate(event, viewer, controller),
            _ => None,
        }
    }
}

/// Start 事件处理
pub fn delegate(
    event: &LifeCycle,
    _viewer: &Viewer,
    _controller: &mut Controller,
) -> Option<Event> {
    match event {
        LifeCycle::Stop => {
            println!("Game stop");
            None
        }
        _ => None,
    }
}
